/**
 * Created by zhubuqing on 2018/3/24.
 */
// 导入变量
var uploading = true;

// 时间类
var teacherInfoBirthday = "";
var courseStartTime = "";
var courseEndTime = "";

// 请求地址
var getSchoolByIdUrl = baseUrl + "/schoolInfoUpdate/getSchoolById";
var getSchoolYearUrl = baseUrl + "/schoolInformationManager/getSchoolYear";
var getTeacherListUrl = baseUrl + "/schoolInformationManager/getTeacherList";
var getSchoolSonBySchoolIdAndSchoolYearNumUrl = baseUrl + "/schoolInformationManager/getBySchoolIdAndSchoolYearNum";
var getCourseNumUrl = baseUrl + "/schoolInformationManager/getCourseList";
var getCourseUrl = baseUrl + "/schoolInformationManager/getAllCourseList";
var getTeacherByTeacherIdUrl = baseUrl + "/schoolInformationManager/getTeacherList";
var getBookUrl = baseUrl + "/schoolInformationManager/searchBook";
var getBookSonUrl = baseUrl + "/schoolInformationManager/searchBookSon";
var getBookSonByBookIdUrl = baseUrl + "/schoolInformationManager/getBookSonByBookId";
var getPracticeTeachingUrl = baseUrl + "/schoolInformationManager/listPracticeTeaching";
var getCourseByCourseIdUrl = baseUrl + "/schoolInformationManager/getCourseByCourseId";
var getBookByBookIdUrl = baseUrl + "/schoolInformationManager/getBookByBookId";
var getPracticeTeachingByPracticeTeachingIdUrl = baseUrl + "/schoolInformationManager/getPracticeTeachingByPracticeTeachingId";
var getSubjectConstructionListUrl = baseUrl + "/schoolInformationManager/getSubjectConstructionList";
var getSubjectConstructionBySubjectConstructionIdUrl = baseUrl + "/schoolInformationManager/getSubjectConstructionBySubjectConstructionId";
var deleteSubjectConstructionUrl = baseUrl + "/schoolInformationManager/deleteSubjectConstructionById";
var listCurriculumConstructionUrl = baseUrl + "/schoolInformationManager/listCurriculumConstruction";
var getCurriculumConstructionByIdUrl = baseUrl + "/schoolInformationManager/getCurriculumConstructionById";
var deleteCurriculumConstructionByIdUrl = baseUrl + "/schoolInformationManager/deleteCurriculumConstructionById";
var listSchoolDynamicsUrl = baseUrl + "/schoolInformationManager/listSchoolDynamics";

var updateTeacherUrl = baseUrl + "/schoolInformationManager/updateTeacher";
var deleteTeacherUrl = baseUrl + "/schoolInformationManager/deleteTeacher";
var updateCourseUrl = baseUrl + "/schoolInformationManager/updateCourse";
var deleteCourseUrl = baseUrl + "/schoolInformationManager/deleteCourse";
var addBookSonUrl = baseUrl + "/schoolInformationManager/addBookSon";
var updateBookSonUrl = baseUrl + "/schoolInformationManager/updateBookSon";
var updatePracticeTeachingUrl = baseUrl + "/schoolInformationManager/updatePracticeTeaching";
var addPracticeTeachingUrl = baseUrl + "/schoolInformationManager/addPracticeTeaching";
var deletePracticeTeachingUrl = baseUrl + "/schoolInformationManager/deletePracticeTeaching";
var updateSubjectConstructionUrl = baseUrl + "/schoolInformationManager/updateSubjectConstruction";
var addSubjectConstructionUrl = baseUrl + "/schoolInformationManager/addSubjectConstruction";
var updateCurriculumConstructionUrl = baseUrl + "/schoolInformationManager/updateCurriculumConstruction";
var addCurriculumConstructionUrl = baseUrl + "/schoolInformationManager/addCurriculumConstruction";
var deleteSchoolDynamicsUrl = baseUrl + "/schoolInformationManager/deleteSchoolDynamics";
var addTeacherUrl = baseUrl + "/schoolInformationManager/addTeacher";
var addCourseUrl = baseUrl + "/schoolInformationManager/addCourse";
var addSchoolDynamicsUrl = baseUrl + "/schoolInformationManager/addSchoolDynamics";
var getSchoolDynamicsByIdUrl = baseUrl + "/schoolInformationManager/getSchoolDynamicsById";
var updateSchoolDynamicsUrl = baseUrl + "/schoolInformationManager/updateSchoolDynamics";
var getBookSonByBookSonIdUrl = baseUrl + "/schoolInformationManager/getBookSonByBookSonId";
var addSchoolSonUrl = baseUrl + "/schoolInformationManager/addSchoolSon";

function xxglInit() {
    // 学校信息标签页面
    schoolInfoPage();

    // 获取学校教师信息
    getTeacherList();

    // 学年下拉框监听
    $("#schoolInfoSchoolYear").change(function () {
        // 获取本科、硕士、博士生人数
        getStudentNum();

        // 获取思政课程数量
        getCourseNum();
    })
    $("#courseInfoSchoolYear").change(function () {
        // 获取课表信息（课表信息标签页）
        getCourse();
    })
    $("#bookSonSchoolYear").change(function () {
        // 获取教材使用情况（教材使用情况表）FROM:addSchoolYear(res)
        getInfoManagerBook();
    })
    $("#practiceTeachingSchoolYear").change(function () {
        // 获取实践教学情况
        getPracticeTeaching();
    })
    $("#subjectConstructionSchoolYear").change(function () {
        // 获取学科建设情况
        getSubjectConstruction();
    })
    $("#curriculumConstructionSchoolYear").change(function () {
        // 获取思政类课程建设情况
        getIdeologicalAndPoliticalEducationCourse();
    })
    $("#schoolDynamicsSchoolYear").change(function () {
        // 获取本校动态
        listSchoolDynamics();
    });

    /********************************** picUtil **********************************/

    $("#schoolDynamicsPic").change(function () {
        var files = this.files;
        $.each(files, function (i, e) {
            var fileReader = new FileReader();
            fileReader.readAsDataURL(e);
            e.mark = Math.random();
            fileReader.onload = function () {
                $("#schoolDynamicsSlPic").attr("src", this.result);
            }
        })
    })

    $("#updateSchoolDynamicsPic").change(function () {
        var files = this.files;
        $.each(files, function (i, e) {
            var fileReader = new FileReader();
            fileReader.readAsDataURL(e);
            e.mark = Math.random();
            fileReader.onload = function () {
                $("#updateSchoolDynamicsSlPic").attr("src", this.result);
            }
        })
    })
}

// 学校信息标签页面
function schoolInfoPage() {
    // 获取学年
    getSchoolYear();

    // 获取学校
    getSchoolById();
}

// 获取学年，添加学年HTML FROM:schoolInfoPage()
function getSchoolYear() {
    commonAjax(getSchoolYearUrl, "", "addSchoolYear", "GET");
}
function addSchoolYear(res) {
    var resultData = res.obj;
    var schoolYearHtml = "";
    for (var i = 0; i < resultData.length; i++) {
        var schoolYearMap = {
            schoolYearNum: resultData[i].schoolYearNum,
            schoolYear: resultData[i].schoolYear
        };

        schoolYearHtml += "<option schoolYearNum='" + resultData[i].schoolYearNum + "'>" + resultData[i].schoolYear + "</option>";
    }
    $("#schoolInfoSchoolYear").html(schoolYearHtml);
    $("#courseInfoSchoolYear").html(schoolYearHtml);
    $("#bookSonSchoolYear").html(schoolYearHtml);
    $("#practiceTeachingSchoolYear").html(schoolYearHtml);
    $("#subjectConstructionSchoolYear").html(schoolYearHtml);
    $("#curriculumConstructionSchoolYear").html(schoolYearHtml);
    $("#schoolDynamicsSchoolYear").html(schoolYearHtml);

    // 获取本科、硕士、博士生人数
    getStudentNum();

    // 获取思政课程数量
    getCourseNum();

    // 获取课表信息（课表信息标签页）
    getCourse();

    // 获取教材使用情况（教材使用情况表）FROM:addSchoolYear(res)
    getInfoManagerBook();

    // 获取实践教学情况
    getPracticeTeaching();

    // 获取学科建设情况
    getSubjectConstruction();

    // 获取思政类课程建设情况
    getIdeologicalAndPoliticalEducationCourse();

    // 获取本校动态
    listSchoolDynamics();
}

// 获取学校信息，添加学校HTML FROM:schoolInfoPage()
function getSchoolById() {
    var data = {
        schoolId: schoolId // 测试用需要修改
    };
    commonAjax(getSchoolByIdUrl, data, "addSchoolInfo", "GET");
}
function addSchoolInfo(res) {
    var resultData = res.obj;
    $("#schoolName").html(resultData.schoolName);
    $("#alertSchoolName").html(resultData.schoolName);
}

// 获取学校教师信息，添加学校HTML（教师部分）
function getTeacherList() {
    var data = {
        schoolId: schoolId
    }
    commonAjax(getTeacherListUrl, data, "addSchoolInfoTeacherInfo", "GET");
}
function addSchoolInfoTeacherInfo(res) {
    var resultData = res.obj;

    // 思政专职教师人数
    var ideologyTeacherNumber = resultData.length;

    // 教授人数
    var professorNumber = 0;

    // 副教授人数
    var associateProfessorNumber = 0;

    for (var i = 0; i < resultData.length; i++) {
        if (resultData[i].positional == "PROFESSOR") {
            professorNumber++;
        }
        if (resultData[i].positional == "ASSOCIATE_PROFESSOR") {
            associateProfessorNumber++;
        }
    }

    $("#ideologyTeacherNumber").html(ideologyTeacherNumber);
    $("#alertIdeologyTeacherNumber").val(ideologyTeacherNumber);
    $("#professorNumber").html(professorNumber);
    $("#alertProfessorNumber").val(professorNumber);
    $("#associateProfessorNumber").html(associateProfessorNumber);
    $("#alertAssociateProfessorNumber").val(associateProfessorNumber);

    addTeacherInfo(resultData);
}
// 教师信息标签页面添加 FROM:addSchoolInfoTeacherInfo(res)
function addTeacherInfo(resultData) {
    var teacherInfo = "";
    for (var i = 0; i < resultData.length; i++) {
        var resultDataI = juge(resultData[i]);
        teacherInfo += "<tr teacherId='" + resultDataI.id + "'>";
        teacherInfo += "<td style='overflow: hidden;white-space: nowrap;text-overflow: ellipsis;width: 67px'><a href='#myModalteachermes' data-toggle='modal' ><span onclick=addGetAlertTeacherInfo('" + resultDataI.id + "')>" + resultDataI.teacherName + "</span></a></td>";
        teacherInfo += "<td><span>" + changeTeacherSex(resultDataI.sex) + "</span></td>";
        teacherInfo += "<td><span>" + changeTimeBirth(resultDataI.birthday) + "</span></td>";
        teacherInfo += "<td width='100px'><span>" + resultDataI.phone + "</span></td>";
        teacherInfo += "<td><span>" + resultDataI.coursesOffered + "</span></td>";
        teacherInfo += "<td><span>" + changeTeacherPositionalEnum(resultDataI.positional) + "</span></td>";
        teacherInfo += "<td><span>" + changeTeacherDuties(resultDataI.duties) + "</span></td>";
        teacherInfo += "<td><span>" + changeTeacherEducation(resultDataI.education) + "</span></td>";
        teacherInfo += "<td><span>" + limitLength(16, resultDataI.researchDirection) + "</span></td>";
        teacherInfo += "<td><span>" + limitLength(16, resultDataI.representativeWorksPapers) + "</span></td>";
        teacherInfo += "<td><span>" + limitLength(16, resultDataI.awardWinning) + "</span></td>";
        teacherInfo += "<td><span>" + resultDataI.schoolyear + "学时</span></td>";
        teacherInfo += "<td><a data-toggle='modal' data-target='#myModal2'><span onclick=getUpdateTeacherInfo('" + resultDataI.id + "')>编辑</span></a>&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;<a><span onclick=deleteTeacher('" + resultDataI.id + "')>删除</span></a></td>";
        teacherInfo += "</tr>";
    }
    $("#teacherInfo").html(teacherInfo);
}
function addGetAlertTeacherInfo(id) {
    var data = {
        id: id
    };
    commonAjax(getTeacherByTeacherIdUrl, data, "addAlertTeacherInfo", "GET");
}
// 点击姓名获取教师详情 FROM:addTeacherInfo(resultData)
function addAlertTeacherInfo(res) {
    var teacher = (res.obj)[0];
    if (teacher != null || teacher != undefined) {
        $("#alertTeacherName").html(teacher.teacherName);
        $("#alertEducation").html(changeTeacherEducation(teacher.education));
        $("#alertGraduateSchool").html(teacher.graduateSchool);
        $("#alertLastEducation").html(changeTeacherEducation(teacher.education));
        $("#alertSex").html(changeTeacherSex(teacher.sex));
        $("#alertLastGraduateSchool").html(teacher.graduateSchool);
        $("#alertBirthday").html(changeTimeBirth(teacher.birthday));
        $("#alertSchoolYear").html(teacher.schoolyear);
        $("#alertPositional").html(changeTeacherPositionalEnum(teacher.positional));
        $("#alertDuties").html(changeTeacherDuties(teacher.duties));
        $("#alertResearchDirection").html(teacher.researchDirection);
        $("#alertAwardWinning").html(teacher.awardWinning);
        $("#alertRepresentativeWorksPapers").html(teacher.representativeWorksPapers);
        $("#alertPhone").html(teacher.phone);
        $("#alertEmail").html(teacher.email);
    } else {
        alert("无此教师信息！");
        location.reload();
    }
}
function getUpdateTeacherInfo(teacherId) {
    var data = {
        id: teacherId
    };
    commonAjax(getTeacherByTeacherIdUrl, data, "addUpdateTeacher", "GET");
}
function addUpdateTeacher(res) {
    var resultData = res.obj;
    $("#teacherInfoUpdateName").val(resultData[0].teacherName);
    if (resultData[0].sex == "M") {
        $("#teacherInfoUpdateSex").html("<option>男</option><option>女</option>");
    } else {
        $("#teacherInfoUpdateSex").html("<option>女</option><option>男</option>");
    }

    teacherInfoBirthday = resultData[0].birthday;

    $("#teacherInfoUpdateBirthday").val(changeTime(resultData[0].birthday));
    $("#teacherInfoUpdatePhone").val(resultData[0].phone);
    $("#teacherInfoUpdateEmail").val(resultData[0].email);
    $("#teacherInfoUpdateCoursesOffered").val(resultData[0].coursesOffered);
    var positional = '<option positional="' + resultData[0].positional + '">' + changeTeacherPositionalEnum(resultData[0].positional) + '</option>';
    positional += '<option positional="LECTURER">讲师</option>';
    positional += '<option positional="PROFESSOR">教授</option>';
    positional += '<option positional="ASSOCIATE_PROFESSOR">副教授</option>';
    $("#teacherInfoUpdatePositional").html(positional);
    var duties = '<option duties="' + resultData[0].duties + '">' + changeTeacherDuties(resultData[0].duties) + '</option>';
    duties += '<option duties="YUAN_ZHANG">院长</option>';
    duties += '<option duties="FU_YUAN_ZHANG">副院长</option>';
    duties += '<option duties="SHU_JI">书记</option>';
    duties += '<option duties="FU_SHU_JI">副书记</option>';
    duties += '<option duties="KE_YAN_SHI_ZHU_REN">科研室主任</option>';
    duties += '<option duties="XUE_KE_DAI_TOU_REN">学科带头人</option>';
    duties += '<option duties="WU">无</option>';
    $("#teacherInfoUpdateDuties").html(duties);
    var education = '<option education="' + resultData[0].education + '">' + changeTeacherEducation(resultData[0].education) + '</option>';
    education += '<option education="UNDERGRADUATE">本科</option>';
    education += '<option education="POSTGRADUATE">硕士研究生</option>';
    education += '<option education="DOCTOR">博士研究生</option>';
    $("#teacherInfoUpdateEducation").html(education);
    $("#teacherInfoUpdateGraduateSchool").val(resultData[0].graduateSchool);
    $("#teacherInfoUpdateSchoolyear").val(resultData[0].schoolyear);

    $("#teacherInfoUpdateResearchDirection").val(resultData[0].researchDirection);
    $("#teacherInfoUpdateAwardWinning").val(resultData[0].awardWinning);
    $("#teacherInfoUpdateButton").html("<button type='button' class='btn btn-default' data-dismiss='modal'>取消</button><button type='button' class='btn btn-danger'><span onclick=updateTeacherInfo('" + resultData[0].id + "')>保存</span></button>")
}
function updateTeacherInfo(teacherId) {
    if (changeTime(teacherInfoBirthday) != changeTime($("#teacherInfoUpdateBirthday").val())) {
        teacherInfoBirthday = $("#teacherInfoUpdateBirthday").val();
    }

    var teacherName = $("#teacherInfoUpdateName").val();
    var sex = "";
    if ($("#teacherInfoUpdateSex option:selected").text() == "男") {
        sex = "M"
    } else {
        sex = "F";
    }
    var birthday = teacherInfoBirthday;
    var phone = $("#teacherInfoUpdatePhone").val();
    var email = $("#teacherInfoUpdateEmail").val();
    var coursesOffered = $("#teacherInfoUpdateCoursesOffered").val();
    var positional = $("#teacherInfoUpdatePositional option:selected").attr("positional");
    var duties = $("#teacherInfoUpdateDuties option:selected").attr("duties");
    var education = $("#teacherInfoUpdateEducation option:selected").attr("education");
    var graduateSchool = $("#teacherInfoUpdateGraduateSchool").val();
    var schoolyear = $("#teacherInfoUpdateSchoolyear").val();
    var researchDirection = $("#teacherInfoUpdateResearchDirection").val();
    var awardWinning = $("#teacherInfoUpdateAwardWinning").val();

    var data = {
        id: teacherId,
        birthday: birthday,
        phone: phone,
        email: email,
        coursesOffered: coursesOffered,
        positional: positional,
        duties: duties,
        education: education,
        graduateSchool: graduateSchool,
        schoolyear: schoolyear,
        researchDirection: researchDirection,
        awardWinning: awardWinning
    }

    commonAjax(updateTeacherUrl, data, "updateTeacher", "POST");
}
function updateTeacher(res) {
    if (res.obj == "SUCCESS") {
        alert("修改成功");
        location.reload();
    } else {
        return;
    }
}
function deleteTeacher(teacherId) {
    var data = {
        id: teacherId
    };

    commonAjax(deleteTeacherUrl, data, "deleteTeacherResult", "POST");
}
function deleteTeacherResult(res) {
    if (res.obj == "SUCCESS") {
        alert("删除成功");
        location.reload();
    } else {
        return;
    }
}
function addTeacher() {
    var teacherName = $("#teacherName").val();
    var sex = $("#teacherSex option:selected").attr("sex");
    var birthday = $("#teacherBirthday").val();
    var phone = $("#phone").val();
    var email = $("#email").val();
    var coursesOffered = $("#coursesOffered").val();
    var positional = $("#positional option:selected").attr("positional");
    var duties = $("#duties option:selected").attr("duties");
    var education = $("#education option:selected").attr("education");
    var graduateSchool = $("#graduateSchool").val();
    var schoolyear = $("#teacherSchoolYear").val();
    var researchDirection = $("#researchDirection").val();
    var researchFindings = $("#researchFindings").val();
    var awardWinning = $("#awardWinning").val();

    var data = {
        schoolId: schoolId,
        password: "123450",
        schoolName: nowSchoolName,
        teacherName: teacherName,
        username: schoolId + teacherName,
        sex: sex,
        birthday: birthday,
        phone: phone,
        email: email,
        coursesOffered: coursesOffered,
        positional: positional,
        duties: duties,
        education: education,
        graduateSchool: graduateSchool,
        schoolyear: schoolyear,
        researchDirection: researchDirection,
        researchFindings: researchFindings,
        awardWinning: awardWinning
    }

    commonAjax(addTeacherUrl, data, addTeacherRes, "POST");
}
function addTeacherRes(res) {
    if (res.obj == "SUCCESS") {
        alert("操作成功");
        location.reload();
    } else if (res.obj == "ERROR") {
        alert("教师已存在");
    } else {
        return;
    }
}
// 导入教师
function inputInTeacher() {
    if (!uploading) {
        return;
    }
    uploading = false;
    var baseModel = ["num", "teacherName", "sex", "birthday", "phone", "email", "coursesOffered", "positional", "duties", "education", "graduateSchool",
        "schoolyear", "researchDirection", "awardWinning", "representativeWorksPapers", "academicDegree"];
    var str = JSON.stringify(baseModel);

    var formData = new FormData();
    formData.append("inputFile", $("#inputFile")[0].files[0]);
    formData.append("baseModel", str);
    formData.append("schoolId", schoolId);
    $.ajax({
        url: "/schoolInformationManager/putInTeacher",
        type: 'POST',
        cache: false,
        data: formData,
        processData: false,
        contentType: false,
        // dataType: "json",
        beforeSend: function () {
            uploading = false;
        },
        success: function (data) {
            if (data === "SUCCESS") {
                alert("上传成功");
                location.reload();
            } else {
                alert("上传失败，请重试！");
            }
            uploading = true;
        },
        error: function (err) {
            // alert(err);
            alert("服务器异常！");
            uploading = true;
        }
    });
}

// 获取本科、硕士、博士生人数 FROM:addSchoolYear(res)
function getStudentNum() {
    var schoolYearNum = $("#schoolInfoSchoolYear option:selected").attr("schoolYearNum");

    var data = {
        schoolYearNum: schoolYearNum,
        schoolId: schoolId
    }

    commonAjax(getSchoolSonBySchoolIdAndSchoolYearNumUrl, data, "addStudentNum", "GET");
}
function addStudentNum(res) {
    var resultData = res.obj;
    if (theSchoolType == 1) {
        if (resultData == null) {
            $("#undergraduateNumber").html(0);
            $("#postgraduateNumber").html(0);
            $("#doctoralStudentNumber").html(0);
            $("#alertStudentNumber").val(0);
            $("#alertSStudentNumber").val(0);
            $("#alertBStudentNumber").val(0);
            return;
        }
        $("#undergraduateNumber").html(resultData.undergraduateNumber);
        $("#postgraduateNumber").html(resultData.postgraduateNumber);
        $("#doctoralStudentNumber").html(resultData.doctoralStudentNumber);
        $("#alertStudentNumber").val(parseInt(resultData.undergraduateNumber));
        $("#alertSStudentNumber").val(parseInt(resultData.postgraduateNumber));
        $("#alertBStudentNumber").val(parseInt(resultData.doctoralStudentNumber));

        var shuoShiBoShiHtml = '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button><button type="button" class="btn btn-danger" onclick=addShuoShiAndBoShi("' + resultData.id + '")>保存</button>';
        $("#addShuoShiAndBoShi").html(shuoShiBoShiHtml);
    } else {
        $("#undergraduateNumber").html(resultData.undergraduateNumber);
        $("#alertStudentNumber").val(resultData.undergraduateNumber);
        $("#postgraduateNumberSign").hide();
        $("#doctoralStudentNumberSign").hide();
        $("#postgraduateNumber").hide();
        $("#doctoralStudentNumber").hide();
        $("#alertSStudentNumber").hide();
        $("#alertBStudentNumber").hide();
        $("#sStudentNumber").hide();
        $("#bStudentNumber").hide();
        $("#atSchoolStudentNumber").html("在校生人数");
        $("#atSchoolStudentNumberSec").html("在校生人数");

        var shuoShiBoShiHtml = '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button><button type="button" class="btn btn-danger" onclick=addZaiXianXueSheng("' + resultData.id + '")>保存</button>';
        $("#addShuoShiAndBoShi").html(shuoShiBoShiHtml);
    }
}
function addZaiXianXueSheng(id) {
    if (id == "null" || id == undefined) {
        id = 0;
    }
    var data = {
        id: id,
        undergraduateNumber: parseInt($("#alertStudentNumber").val()),
        schoolId: this.schoolId,
        schoolYearNum: $("#schoolInfoSchoolYear option:selected").attr("schoolYearNum")
    };

    commonAjax(addSchoolSonUrl, data, "addShuoShiAndBoShiRes", "POST");
}
function addShuoShiAndBoShi(id) {
    if (id == "null" || id == undefined) {
        id = 0;
    }
    var data = {
        id: id,
        undergraduateNumber: parseInt($("#alertStudentNumber").val()),
        postgraduateNumber: parseInt($("#alertSStudentNumber").val()),
        doctoralStudentNumber: parseInt($("#alertBStudentNumber").val()),
        schoolId: this.schoolId,
        schoolYearNum: $("#schoolInfoSchoolYear option:selected").attr("schoolYearNum")
    };

    commonAjax(addSchoolSonUrl, data, "addShuoShiAndBoShiRes", "POST");
}
function addShuoShiAndBoShiRes(res) {
    if (res.obj == "SUCCESS") {
        alert("修改成功");
        location.reload();
    } else {
        return;
    }
}

// 获取思政课程数量 FROM:addSchoolYear(res)
function getCourseNum() {
    var schoolYearNum = $("#schoolInfoSchoolYear option:selected").attr("schoolYearNum");

    var data = {
        schoolYearNum: schoolYearNum,
        schoolId: schoolId
    }

    commonAjax(getCourseNumUrl, data, "addCourseNum", "GET");
}

function addCourseNum(res) {
    $("#ideologyElectiveCourseNumber").html(res.obj);
    $("#alertIdeologyElectiveCourseNumber").val(res.obj);
}

// 获取课表信息（课表信息标签页）FROM:addSchoolYear(res)
function getCourse() {
    var schoolYearNum = $("#courseInfoSchoolYear option:selected").attr("schoolYearNum");

    var data = {
        schoolYearNum: schoolYearNum,
        schoolId: schoolId
    }

    commonAjax(getCourseUrl, data, "addCourse", "GET");
}

function addCourse(res) {
    var courseHtml = "";
    var resultData = res.obj;
    for (var i = 0; i < resultData.length; i++) {
        var resultDataI = juge(resultData[i]);

        courseHtml += "<tr courseId='" + resultDataI.id + "'>";
        courseHtml += "<td><span>" + nowSchoolName + "</span></td>";
        courseHtml += "<td><span>" + resultDataI.courseName + "</span></td>";
        courseHtml += "<td><span>" + changeTime(resultDataI.startTime) + "</span></td>";
        courseHtml += "<td><span>" + changeTime(resultDataI.endTime) + "</span></td>";
        courseHtml += "<td><span>" + resultDataI.classTime + "</span></td>"
        courseHtml += "<td><a data-toggle='modal' data-target='#myModalteachermes'><span onclick=getTeacherByTeacherName('" + resultDataI.teacher + "')>" + resultData[i].teacher + "</span></a></td>";
        courseHtml += "<td><span>" + changeCourseRequiredElective(resultDataI.requiredElective) + "</span></td>";
        courseHtml += "<td><span>" + resultDataI.choiceOfCoursesNumber + "</span></td>";
        courseHtml += "<td><span>" + resultDataI.classPlace + "</span></td>";
        courseHtml += "<td><span>" + resultDataI.credit + "</span></td>";
        courseHtml += "<td><span>" + resultDataI.hours + "</span></td>";
        courseHtml += "<td><a data-toggle='modal' data-target='#myModal4'><span onclick=getUpdateCourseInfo('" + resultDataI.id + "')>编辑</span></a>&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;<a><span onclick=deleteCourse('" + resultDataI.id + "')>删除</span></a></td>";
        courseHtml += "</tr>";
    }
    $("#courseInfo").html(courseHtml);
}

function getTeacherByTeacherName(name) {
    var data = {
        teacherName: name
    };

    commonAjax(getTeacherByTeacherIdUrl, data, "addCourseAlertTeacherInfo", "GET");
}

function addCourseAlertTeacherInfo(res) {
    addAlertTeacherInfo(res);
}

function getUpdateCourseInfo(courseId) {
    var data = {
        id: courseId
    };
    commonAjax(getCourseByCourseIdUrl, data, "getCourseByCourseId", "GET");
}

function getCourseByCourseId(res) {
    var resultData = res.obj;
    courseStartTime = resultData.startTime;
    courseEndTime = resultData.endTime;
    $("#courseUpdateSchool").val(nowSchoolName);
    $("#courseUpdateStartTime").val(changeTime(resultData.startTime));
    $("#courseUpdateEndTime").val(changeTime(resultData.endTime));
    $("#courseUpdateClassTime").val(resultData.classTime);
    $("#courseUpdateTeacher").val(resultData.teacher);
    if (resultData.requiredElective == "REQUIRED") {
        $("#courseUpdateRequiredElective").html("<option>必修</option><option>选修</option>");
    } else {
        $("#courseUpdateRequiredElective").html("<option>选修</option><option>必修</option>");
    }
    $("#courseUpdateChoiceOfCoursesNumber").val(resultData.choiceOfCoursesNumber);
    $("#courseUpdateClassPlace").val(resultData.classPlace);
    $("#courseUpdateCredit").val(resultData.credit);
    $("#courseUpdateHours").val(resultData.hours);
    $("#courseUpdateButton").html("<button type='button' class='btn btn-default' data-dismiss='modal'>取消</button><button type='button' class='btn btn-danger'><span onclick=updateCourseInfo('" + resultData.id + "')>保存</span></button>");
}

function updateCourseInfo(courseId) {
    if (changeTime(courseStartTime) != changeTime($("#courseUpdateStartTime").val())) {
        courseStartTime = $("#courseUpdateStartTime").val();
    }
    if (changeTime(courseEndTime) != changeTime($("#courseUpdateEndTime").val())) {
        courseEndTime = $("#courseUpdateEndTime").val();
    }
    var nowSchoolName = $("#courseUpdateSchool").val();
    var startTime = courseStartTime;
    var endTime = courseEndTime;
    var classTime = $("#courseUpdateClassTime").val();
    var teacher = $("#courseUpdateTeacher").val();
    var requiredElective = "";
    if ($("#courseUpdateRequiredElective option:selected").text() == "必修") {
        requiredElective = "REQUIRED";
    }
    else {
        requiredElective = "ELECTIVE";
    }
    var choiceOfCoursesNumber = $("#courseUpdateChoiceOfCoursesNumber").val();
    var classPlace = $("#courseUpdateClassPlace").val();
    var credit = $("#courseUpdateCredit").val();
    var hours = $("#courseUpdateHours").val();

    var data = {
        id: courseId,
        schoolName: nowSchoolName,
        startTime: startTime,
        endTime: endTime,
        classTime: classTime,
        teacher: teacher,
        requiredElective: requiredElective,
        choiceOfCoursesNumber: choiceOfCoursesNumber,
        classPlace: classPlace,
        credit: credit,
        hours: hours
    }

    commonAjax(updateCourseUrl, data, "updateCourse", "POST");
}

function updateCourse(res) {
    if (res.obj == "SUCCESS") {
        alert("修改成功");
        location.reload();
    } else {
        return;
    }
}

function deleteCourse(courseId) {
    var data = {
        id: courseId
    };

    commonAjax(deleteCourseUrl, data, "deleteCourseResult", "POST");
}

function deleteCourseResult(res) {
    if (res.obj == "SUCCESS") {
        alert("删除成功");
        location.reload();
    } else {
        return;
    }
}

function addTheCourse() {
    var schoolYearNum = $("#courseInfoSchoolYear option:selected").attr("schoolYearNum");
    var courseName = $("#courseName").val();
    var startTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    var classTime = $("#classTime").val();
    var teacher = $("#teacher").val();
    var requiredElective = "";
    if ($("#requiredElective").val() == "必修") {
        requiredElective = "REQUIRED";
    } else {
        requiredElective = "ELECTIVE";
    }
    var choiceOfCoursesNumber = $("#choiceOfCoursesNumber").val();
    var classPlace = $("#classPlace").val();
    var credit = $("#credit").val();
    var hours = $("#hours").val();

    var data = {
        courseName: courseName,
        startTime: startTime,
        endTime: endTime,
        classTime: classTime,
        teacher: teacher,
        requiredElective: requiredElective,
        choiceOfCoursesNumber: choiceOfCoursesNumber,
        classPlace: classPlace,
        credit: credit,
        hours: hours,
        schoolId: schoolId,
        schoolName: nowSchoolName,
        schoolYearNum: schoolYearNum
    }

    commonAjax(addCourseUrl, data, "addTheCourseRes", "POST");
}

function addTheCourseRes(res) {
    if (res.obj == "SUCCESS") {
        alert("操作成功");
        location.reload();
    } else {
        return;
    }
}

// 导入课程
function inputInCourse() {
    if (!uploading) {
        return;
    }
    uploading = false;
    var baseModel = ["num", "courseName", "startTime", "endTime", "classTime", "teacher", "requiredElective", "choiceOfCoursesNumber", "classPlace",
        "credit", "hours", "isGraduateClazz"];
    var str = JSON.stringify(baseModel);

    var formData = new FormData();
    formData.append("inputFile", $("#inputFile1")[0].files[0]);
    formData.append("baseModel", str);
    formData.append("schoolYearNum", $("#courseInfoSchoolYear option:selected").attr("schoolYearNum"));
    $.ajax({
        url: "/schoolInformationManager/putInCourse",
        type: 'POST',
        cache: false,
        data: formData,
        processData: false,
        contentType: false,
        // dataType: "json",
        beforeSend: function () {
            uploading = false;
        },
        success: function (data) {
            if (data === "SUCCESS") {
                alert("上传成功");
                location.reload();
            } else {
                alert("上传失败，请重试！");
            }
            uploading = true;
        },
        error: function (err) {
            // alert(err);
            alert("服务器异常！");
            uploading = true;
        }
    });
}

//获取教材使用情况（教材使用情况表）FROM:addSchoolYear(res)
function getInfoManagerBook() {
    var schoolYearNum = $("#bookSonSchoolYear option:selected").attr("schoolYearNum");

    var data = {
        bookId: 0,
        schoolId: schoolId,
        schoolYearNum: schoolYearNum
    }

    commonAjax(getBookUrl, "", "getBookSonByBookId", "GET");

    commonAjax(getBookSonUrl, data, "getBookSonRes", "GET");
}

function getBookSonRes(res) {
    var theUseOfTheTeachingMaterialsInTheElectiveCourseOfIdeologicalAndPoliticalAffairsHtml = "";

    var resultData = res.obj.content;

    for (var i = 0; i < resultData.length; i++) {
        theUseOfTheTeachingMaterialsInTheElectiveCourseOfIdeologicalAndPoliticalAffairsHtml += "<tr ownBookSonId='" + resultData[i].id + "'>";
        theUseOfTheTeachingMaterialsInTheElectiveCourseOfIdeologicalAndPoliticalAffairsHtml += "<td><span>" + resultData[i].className + "</span></td>";
        theUseOfTheTeachingMaterialsInTheElectiveCourseOfIdeologicalAndPoliticalAffairsHtml += "<td><span>" + resultData[i].classTeacher + "</span></td>";
        theUseOfTheTeachingMaterialsInTheElectiveCourseOfIdeologicalAndPoliticalAffairsHtml += "<td><span>" + resultData[i].bookName + "</span></td>";
        theUseOfTheTeachingMaterialsInTheElectiveCourseOfIdeologicalAndPoliticalAffairsHtml += "<td><span>" + resultData[i].outOfTheSociety + "</span></td>";
        theUseOfTheTeachingMaterialsInTheElectiveCourseOfIdeologicalAndPoliticalAffairsHtml += "<td><span>" + resultData[i].editor + "</span></td>";
        theUseOfTheTeachingMaterialsInTheElectiveCourseOfIdeologicalAndPoliticalAffairsHtml += "<td><span>" + resultData[i].useVersion + "</span></td>";
        theUseOfTheTeachingMaterialsInTheElectiveCourseOfIdeologicalAndPoliticalAffairsHtml += "<td><span>" + ((resultData[i].isMarxProject == 1) ? "是" : "否") + "</span></td>";
        theUseOfTheTeachingMaterialsInTheElectiveCourseOfIdeologicalAndPoliticalAffairsHtml += "<td><span>" + resultData[i].userNumber + "</span></td>";
        theUseOfTheTeachingMaterialsInTheElectiveCourseOfIdeologicalAndPoliticalAffairsHtml += "<td><a data-toggle='modal' data-target='#myModal18'><span onclick=updateMyBookSon('" + resultData[i].id + "')>编辑</span></a></td>";
        theUseOfTheTeachingMaterialsInTheElectiveCourseOfIdeologicalAndPoliticalAffairsHtml += "</tr>";
    }

    $("#theUseOfTheTeachingMaterialsInTheElectiveCourseOfIdeologicalAndPoliticalAffairs").html(theUseOfTheTeachingMaterialsInTheElectiveCourseOfIdeologicalAndPoliticalAffairsHtml);
}

function updateMyBookSon(bookSonId) {
    var data = {
        id: bookSonId
    }
    commonAjax(getBookSonByBookSonIdUrl, data, "updateMyBookSonRes", "GET");
}

function updateMyBookSonRes(res) {
    var resultData = res.obj;
    $("#tBookUpdateBookName").val(resultData.bookName);
    $("#tBookUpdateOutOfTheSociety").val(resultData.outOfTheSociety);
    $("#tBookUpdateCourseName").val(resultData.className);
    $("#tBookUpdateTeacher").val(resultData.classTeacher);
    $("#tBookUpdateEditor").val(resultData.editor);
    $("#tBookUpdateUseVersion").val(resultData.useVersion);
    if (resultData.isMarxProject == 1) {
        $("#tBookUpdateIsMarxProject").html("<option>是</option><option>否</option>");
    } else {
        $("#tBookUpdateIsMarxProject").html("<option>否</option><option>是</option>");
    }
    $("#tBookUpdateUserNumber").val(resultData.userNumber);
    $("#tBookUpdateButton").html("<button type='button' class='btn btn-default' data-dismiss='modal'>取消</button><button type='button' class='btn btn-danger'><span onclick=updateBookSonInfo('" + resultData.id + "')>保存</span></button>");
}

function updateBookSonInfo(bookSonId) {
    var bookName = $("#tBookUpdateBookName").val();
    var outOfTheSociety = $("#tBookUpdateOutOfTheSociety").val();
    var className = $("#tBookUpdateCourseName").val();
    var classTeacher = $("#tBookUpdateTeacher").val();
    var editor = $("#tBookUpdateEditor").val();
    var useVersion = $("#tBookUpdateUseVersion").val();
    var isMarxProject = 0;
    if ($("#tBookUpdateIsMarxProject option:selected").text() == "是") {
        isMarxProject = 1;
    }
    var userNumber = $("#tBookUpdateUserNumber").val();

    var data = {
        id: bookSonId,
        bookName: bookName,
        outOfTheSociety: outOfTheSociety,
        className: className,
        classTeacher: classTeacher,
        editor: editor,
        useVersion: useVersion,
        isMarxProject: isMarxProject,
        userNumber: userNumber
    };

    commonAjax(updateBookSonUrl, data, "updateBookSon", "POST");
}

function getBookSonByBookId(res) {
    var theLatestVersionOfTheIdeologicalAndPoliticalTheoryCourseTextbooksHtml = "";
    var zheJiangProvinceUniversityMoralEducationTextbookUseHtml = "";

    var schoolYearNum = $("#bookSonSchoolYear option:selected").attr("schoolYearNum");

    var resultData = res.obj.content;

    for (var i = 0; i < resultData.length; i++) {
        var data = {
            schoolYearNum: schoolYearNum,
            bookId: resultData[i].id
        };

        if (theSchoolType != 1) {
            if (resultData[i].id == 1 || resultData[i].id == 4 || resultData[i].id == 17) {
                continue;
            }
        }

        if (resultData[i].useType == "THE_LATEST_VERSION_OF_THE_IDEOLOGICAL_AND_POLITICAL_THEORY_COURSE_TEXTBOOKS") {
            theLatestVersionOfTheIdeologicalAndPoliticalTheoryCourseTextbooksHtml += "<tr bookId='" + resultData[i].id + "'>";
            theLatestVersionOfTheIdeologicalAndPoliticalTheoryCourseTextbooksHtml += "<td><span>" + resultData[i].bookName + "</span></td>";
            theLatestVersionOfTheIdeologicalAndPoliticalTheoryCourseTextbooksHtml += "<td><span>" + resultData[i].outOfTheSociety + "</span></td>";
            theLatestVersionOfTheIdeologicalAndPoliticalTheoryCourseTextbooksHtml += "<td><span id='textbooks" + resultData[i].id + "'></span></td>";
            theLatestVersionOfTheIdeologicalAndPoliticalTheoryCourseTextbooksHtml += "<td><span id='useVersion" + resultData[i].id + "'></span></td>";
            theLatestVersionOfTheIdeologicalAndPoliticalTheoryCourseTextbooksHtml += "<td><span id='userNumber" + resultData[i].id + "'></span></td>";
            theLatestVersionOfTheIdeologicalAndPoliticalTheoryCourseTextbooksHtml += "<td><a data-toggle='modal' data-target='#myModal7'><span onclick=updateBook('" + resultData[i].id + "')>编辑</span></a></td>";
            theLatestVersionOfTheIdeologicalAndPoliticalTheoryCourseTextbooksHtml += "</tr>";

            commonAjax(getBookSonByBookIdUrl, data, "addBookSon", "GET", "theLatestVersionOfTheIdeologicalAndPoliticalTheoryCourseTextbooks_&_" + resultData[i].id);
        } else if (resultData[i].useType == "THE_USE_OF_THE_TEACHING_MATERIALS_IN_THE_ELECTIVE_COURSE_OF_IDEOLOGICAL_AND_POLITICAL_AFFAIRS") {
            zheJiangProvinceUniversityMoralEducationTextbookUseHtml += "<tr bookId='" + resultData[i].id + "'>";
            zheJiangProvinceUniversityMoralEducationTextbookUseHtml += "<td><span>" + resultData[i].bookName + "</span></td>"
            zheJiangProvinceUniversityMoralEducationTextbookUseHtml += "<td><span>" + resultData[i].outOfTheSociety + "</span></td>";
            zheJiangProvinceUniversityMoralEducationTextbookUseHtml += "<td><span id='textbooks" + resultData[i].id + "'></span></td>";
            zheJiangProvinceUniversityMoralEducationTextbookUseHtml += "<td><span id='useVersion" + resultData[i].id + "'></span></td>";
            zheJiangProvinceUniversityMoralEducationTextbookUseHtml += "<td><span id='userNumber" + resultData[i].id + "'></span></td>";
            zheJiangProvinceUniversityMoralEducationTextbookUseHtml += "<td><a data-toggle='modal' data-target='#myModal7'><span onclick=updateBook('" + resultData[i].id + "')>编辑</span></a></td>";
            zheJiangProvinceUniversityMoralEducationTextbookUseHtml += "</tr>";

            commonAjax(getBookSonByBookIdUrl, data, "addBookSon", "GET", "zheJiangProvinceUniversityMoralEducationTextbookUse_&_" + resultData[i].id);
        }
    }

    $("#theLatestVersionOfTheIdeologicalAndPoliticalTheoryCourseTextbooks").html(theLatestVersionOfTheIdeologicalAndPoliticalTheoryCourseTextbooksHtml);
    $("#zheJiangProvinceUniversityMoralEducationTextbookUse").html(zheJiangProvinceUniversityMoralEducationTextbookUseHtml);
}

function addBookSon(res, param) {
    var resultData = res.obj;

    if (resultData == null) {
        return;
    }

    var type = param.split("_&_")[0];
    var bookId = param.split("_&_")[1];
    if (type == "theLatestVersionOfTheIdeologicalAndPoliticalTheoryCourseTextbooks" || type == "zheJiangProvinceUniversityMoralEducationTextbookUse") {
        if (resultData.textbooks == 0) {
            $("#textbooks" + bookId).html("否");
        } else {
            $("#textbooks" + bookId).html("是");
        }
        $("#useVersion" + bookId).html(resultData.useVersion);
        $("#userNumber" + bookId).html(resultData.userNumber);
    } else if (type == "theUseOfTheTeachingMaterialsInTheElectiveCourseOfIdeologicalAndPoliticalAffairs") {
        $("#className" + bookId).html(resultData.className);
        $("#classTeacher" + bookId).html(resultData.classTeacher);
        $("#editor" + bookId).html(resultData.editor);
        $("#useVersion" + bookId).html(resultData.useVersion);
        $("#isMarxProject" + bookId).html(resultData.isMarxProject);
        $("#userNumber" + bookId).html(resultData.userNumber);
    }
}

function updateBook(bookId) {
    var data = {
        id: bookId
    };
    commonAjax(getBookByBookIdUrl, data, "getBookByBookId", "GET");
}

function getBookByBookId(res) {
    var resultData = res.obj;
    $("#bookUpdateBookName").val(resultData.bookName);
    $("#bookUpdateOutOfTheSociety").val(resultData.outOfTheSociety);
    $("#bookUpdateBookName").attr("disabled", true);
    $("#bookUpdateOutOfTheSociety").attr("disabled", true);

    var data = {
        bookId: resultData.id,
        schoolYearNum: $("#bookSonSchoolYear option:selected").attr("schoolYearNum")
    };

    commonAjax(getBookSonByBookIdUrl, data, "getUpdateBookSon", "GET", resultData.id);
}

function getUpdateBookSon(res, bookId) {
    var resultData = res.obj;
    if (resultData == null) {
        alert("本年度无此教材信息！");
        $("#bookUpdateUseVersion").val("");
        $("#bookUpdateIsMarxProject").html("<option></option><option>是</option><option>否</option>");
        $("#bookUpdateUserNumber").val("");
        $("#bookUpdateButton").html("<button type='button' class='btn btn-default' data-dismiss='modal'>取消</button><button type='button' class='btn btn-danger'><span onclick=updateBookInfo(-1,'" + bookId + "')>保存</span></button>");
        return;
    }
    $("#bookUpdateUseVersion").val(resultData.useVersion);
    if (resultData.textbooks == 1) {
        $("#bookUpdateIsMarxProject").html("<option>是</option><option>否</option>");
    } else {
        $("#bookUpdateIsMarxProject").html("<option>否</option><option>是</option>");
    }
    $("#bookUpdateUserNumber").val(resultData.userNumber);
    $("#bookUpdateButton").html("<button type='button' class='btn btn-default' data-dismiss='modal'>取消</button><button type='button' class='btn btn-danger'><span onclick=updateBookInfo('" + resultData.id + "','" + resultData.bookId + "')>保存</span></button>");
}

function updateBookInfo(bookSonId, bookId) {
    if (bookSonId == -1) {
        var schoolYearNum = $("#bookSonSchoolYear option:selected").attr("schoolYearNum");
        var bookId = bookId;
        var useVersion = $("#bookUpdateUseVersion").val();
        var textbooks = 0;
        if ($("#bookUpdateIsMarxProject option:selected").text() == "是") {
            textbooks = 1;
        }
        var userNumber = $("#bookUpdateUserNumber").val();

        var data = {
            schoolYearNum: schoolYearNum,
            bookId: bookId,
            useVersion: useVersion,
            textbooks: textbooks,
            userNumber: userNumber,
            schoolName: nowSchoolName,
            schoolId: schoolId
        };

        commonAjax(addBookSonUrl, data, "addBookSonResult", "POST");
    } else {
        var className = $("#bookUpdateCourseName").val();
        var classTeacher = $("#bookUpdateTeacher").val();
        var editor = $("#bookUpdateEditor").val();
        var useVersion = $("#bookUpdateUseVersion").val();
        var textbooks = 0;
        if ($("#bookUpdateIsMarxProject option:selected").text() == "是") {
            textbooks = 1;
        }
        var userNumber = $("#bookUpdateUserNumber").val();

        var data = {
            id: bookSonId,
            className: className,
            classTeacher: classTeacher,
            editor: editor,
            useVersion: useVersion,
            schoolName: nowSchoolName,
            textbooks: textbooks,
            userNumber: userNumber
        };

        commonAjax(updateBookSonUrl, data, "updateBookSon", "POST");
    }
}

function addBookSonResult(res) {
    if (res.obj == "SUCCESS") {
        alert("操作成功");
        location.reload();
    } else {
        alert("操作失败");
        return;
    }
}

function updateBookSon(res) {
    if (res.obj == "SUCCESS") {
        alert("操作成功");
        location.reload();
    } else {
        alert("操作失败");
        return;
    }
}

function addBookAndBookSon() {
    var bookName = $("#bookName").val();
    var outOfTheSociety = $("#outOfTheSociety").val();
    var bookId = 0;
    var schoolId = this.schoolId;
    var textbooks = 0;
    var useVersion = $("#useVersion").val();
    var userNumber = $("#userNumber").val();
    var className = $("#className").val();
    var classTeacher = $("#classTeacher").val();
    var editor = $("#editor1").val();
    var isMarxProject = 0;
    if ($("#isMarxProject option:selected").text() == "是") {
        isMarxProject = 1;
    }
    var schoolYearNum = $("#bookSonSchoolYear option:selected").attr("schoolYearNum");
    var schoolName = nowSchoolName;

    var data = {
        bookId: bookId,
        schoolId: schoolId,
        textbooks: textbooks,
        useVersion: useVersion,
        userNumber: userNumber,
        className: className,
        classTeacher: classTeacher,
        editor: editor,
        isMarxProject: isMarxProject,
        schoolYearNum: schoolYearNum,
        schoolName: schoolName,
        bookName: bookName,
        outOfTheSociety: outOfTheSociety
    };

    commonAjax(addBookSonUrl, data, "addBookSonRes", "POST");
}

function addBookSonRes(res) {
    if (res.obj == "SUCCESS") {
        alert("操作成功");
        location.reload();
    } else {
        alert("操作失败");
        return;
    }
}

// 导入教材
function inputInBook() {
    if (!uploading) {
        return;
    }
    uploading = false;
    var baseModel = ["className", "classTeacher", "bookName", "outOfTheSociety", "editor", "useVersion", "isMarxProject", "userNumber"];
    var str = JSON.stringify(baseModel);

    var formData = new FormData();
    formData.append("inputFile", $("#inputFile2")[0].files[0]);
    formData.append("baseModel", str);
    formData.append("schoolYearNum", $("#bookSonSchoolYear option:selected").attr("schoolYearNum"));
    $.ajax({
        url: "/schoolInformationManager/putInBook",
        type: 'POST',
        cache: false,
        data: formData,
        processData: false,
        contentType: false,
        // dataType: "json",
        beforeSend: function () {
            uploading = false;
        },
        success: function (data) {
            if (data === "SUCCESS") {
                alert("上传成功");
                location.reload();
            } else {
                alert("上传失败，请重试！");
            }
            uploading = true;
        },
        error: function (err) {
            // alert(err);
            alert("服务器异常！");
            uploading = true;
        }
    });
}

// 获取实践教学情况
function getPracticeTeaching() {
    var schoolYearNum = $("#practiceTeachingSchoolYear option:selected").attr("schoolYearNum");

    var data = {
        schoolYearNum: schoolYearNum,
        schoolId: schoolId
    };

    commonAjax(getPracticeTeachingUrl, data, "addPracticeTeaching", "GET");
}

function addPracticeTeaching(res) {
    var resultData = res.obj;
    var practiceTeachingListHtml = "";
    for (var i = 0; i < resultData.length; i++) {
        if (i == 0) {
            practiceTeachingListHtml += "<li role='presentation' class='active'><a href='#home' aria-controls='home' role='tab' data-toggle='tab'><span onclick=commonAjax('" + getPracticeTeachingByPracticeTeachingIdUrl + "','id=" + resultData[i].id + "','addSignPracticeTeaching','GET','home')>" + resultData[i].projectName + "</span></a></li>";
            $("#alertHomePracticeTeachingProjectName").html(resultData[i].projectName);
            $("#alertHomePracticeTeachingCredit").html(resultData[i].credit);
            $("#alertHomePracticeTeachingDate").html(changeTime(resultData[i].date));
            $("#alertHomePracticeTeachingTeacher").html(resultData[i].teacher);
            $("#alertHomePracticeTeachingStudentNum").html(resultData[i].studentNum);
            $("#alertHomePracticeTeachingContent").html(resultData[i].content);
            $("#alertHomePracticeTeachingButton").html("<button type='button' class='btn btn-default' data-toggle='modal' data-target='#myModal9'><span onclick=updatePracticeTeaching('" + resultData[i].id + "')>编辑</span></button><button type='button' style='margin-left: 30px' class='btn btn-danger'><span onclick=deletePracticeTeaching('" + resultData[i].id + "')>删除</span></button>");
        } else {
            practiceTeachingListHtml += "<li role='presentation'><a href='#profile' aria-controls='profile' role='tab' data-toggle='tab'><span onclick=commonAjax('" + getPracticeTeachingByPracticeTeachingIdUrl + "','id=" + resultData[i].id + "','addSignPracticeTeaching','GET','profile')>" + resultData[i].projectName + "</span></a></li>";
            $("#alertProfilePracticeTeachingProjectName").html(resultData[i].projectName);
            $("#alertProfilePracticeTeachingCredit").html(resultData[i].credit);
            $("#alertProfilePracticeTeachingDate").html(changeTime(resultData[i].date));
            $("#alertProfilePracticeTeachingTeacher").html(resultData[i].teacher);
            $("#alertProfilePracticeTeachingStudentNum").html(resultData[i].studentNum);
            $("#alertProfilePracticeTeachingContent").html(resultData[i].content);
            $("#alertProfilePracticeTeachingButton").html("<button type='button' class='btn btn-default' data-toggle='modal' data-target='#myModal9'><span onclick=updatePracticeTeaching('" + resultData[i].id + "')>编辑</span></button><button type='button' class='btn btn-danger'><span onclick=deletePracticeTeaching('" + resultData[i].id + "')>删除</span></button>");
        }
    }
    if (resultData.length == 0) {
        $("#home").css("display", "none"); // 隐藏div
        $("#profile").css("display", "none"); // 隐藏div
    } else {
        $("#home").css("display", "block"); // 显示div
        $("#profile").css("display", "none"); // 隐藏div
    }

    $("#practiceTeachingList").html(practiceTeachingListHtml);
}

function addSignPracticeTeaching(res, type) {
    var resultData = res.obj;
    if (type == "home") {
        $("#home").css("display", "block"); // 显示div
        $("#profile").css("display", "none"); // 隐藏div
        $("#alertHomePracticeTeachingProjectName").html(resultData.projectName);
        $("#alertHomePracticeTeachingCredit").html(resultData.credit);
        $("#alertHomePracticeTeachingDate").html(changeTime(resultData.date));
        $("#alertHomePracticeTeachingTeacher").html(resultData.teacher);
        $("#alertHomePracticeTeachingStudentNum").html(resultData.studentNum);
        $("#alertHomePracticeTeachingContent").html(resultData.content);
        $("#alertHomePracticeTeachingButton").html("<button type='button' class='btn btn-default' data-toggle='modal' data-target='#myModal9'><span onclick=updatePracticeTeaching('" + resultData.id + "')>编辑</span></button><button type='button' class='btn btn-danger'><span onclick=deletePracticeTeaching('" + resultData.id + "')>删除</span></button>");
    } else if (type == "profile") {
        $("#profile").css("display", "block"); // 显示div
        $("#home").css("display", "none"); // 隐藏div
        $("#alertProfilePracticeTeachingProjectName").html(resultData.projectName);
        $("#alertProfilePracticeTeachingCredit").html(resultData.credit);
        $("#alertProfilePracticeTeachingDate").html(changeTime(resultData.date));
        $("#alertProfilePracticeTeachingTeacher").html(resultData.teacher);
        $("#alertProfilePracticeTeachingStudentNum").html(resultData.studentNum);
        $("#alertProfilePracticeTeachingContent").html(resultData.content);
        $("#alertProfilePracticeTeachingButton").html("<button type='button' class='btn btn-default' data-toggle='modal' data-target='#myModal9'><span onclick=updatePracticeTeaching('" + resultData.id + "')>编辑</span></button><button type='button' class='btn btn-danger'><span onclick=deletePracticeTeaching('" + resultData.id + "')>删除</span></button>");
    }
}

function updatePracticeTeaching(practiceTeachingId, type) {
    var data = {
        id: practiceTeachingId
    };
    commonAjax(getPracticeTeachingByPracticeTeachingIdUrl, data, "getPracticeTeachingByPracticeTeachingId", "GET");
}

function getPracticeTeachingByPracticeTeachingId(res) {
    var resultData = res.obj;
    $("#PracticeTeachingUpdateProjectName").val(resultData.projectName);
    $("#PracticeTeachingUpdateCredit").val(resultData.credit);
    $("#PracticeTeachingUpdateDate").val(changeTime(resultData.date));
    $("#PracticeTeachingUpdateTeacher").val(resultData.teacher);
    $("#PracticeTeachingUpdateStudentNum").val(resultData.studentNum);
    $("#PracticeTeachingUpdateContent").val(resultData.content);
    $("#PracticeTeachingUpdateButton").html("<button type='button' class='btn btn-default' data-dismiss='modal'>取消</button><button type='button' class='btn btn-danger' onclick=updatePracticeTeachingButton('" + resultData.id + "')>保存</button>");
}

function updatePracticeTeachingButton(id) {
    var projectName = $("#PracticeTeachingUpdateProjectName").val();
    var credit = $("#PracticeTeachingUpdateCredit").val();
    var date = $("#PracticeTeachingUpdateDate").val();
    var teacher = $("#PracticeTeachingUpdateTeacher").val();
    var studentNum = $("#PracticeTeachingUpdateStudentNum").val();
    var content = $("#PracticeTeachingUpdateContent").val();

    var data = {
        id: id,
        projectName: projectName,
        credit: credit,
        date: date,
        teacher: teacher,
        studentNum: studentNum,
        content: content
    };

    commonAjax(updatePracticeTeachingUrl, data, "updatePracticeTeachingInfo", "POST");
}

function updatePracticeTeachingInfo(res) {
    if (res.obj == "SUCCESS") {
        alert("操作成功");
        location.reload();
    } else {
        alert("操作失败");
        return;
    }
}

function savePracticeTeaching() {
    var schoolYearNum = $("#practiceTeachingSchoolYear option:selected").attr("schoolYearNum");
    var projectName = $("#addPracticeTeachingProjectName").val();
    var credit = $("#addPracticeTeachingCredit").val();
    var date = $("#addPracticeTeachingDate").val();
    var teacher = $("#addPracticeTeachingTeacher").val();
    var studentNum = $("#addPracticeTeachingStudentNum").val();
    var content = $("#addPracticeTeachingContent").val();

    var data = {
        projectName: projectName,
        credit: credit,
        date: date,
        teacher: teacher,
        studentNum: studentNum,
        content: content,
        schoolYearNum: schoolYearNum,
        schoolId: schoolId
    };

    commonAjax(addPracticeTeachingUrl, data, "addPracticeTeachingHtml", "POST");
}

function addPracticeTeachingHtml(res) {
    if (res.obj == "SUCCESS") {
        alert("操作成功");
        location.reload();
    } else {
        alert("操作失败");
        return;
    }
}

function deletePracticeTeaching(id) {
    var data = {
        id: id
    };

    commonAjax(deletePracticeTeachingUrl, data, "deletePracticeTeachingResult", "POST");
}

function deletePracticeTeachingResult(res) {
    if (res.obj == "SUCCESS") {
        alert("操作成功");
        location.reload();
    } else {
        alert("操作失败");
        return;
    }
}

// 获取学科建设情况
function getSubjectConstruction() {
    var schoolYearNum = $("#subjectConstructionSchoolYear option:selected").attr("schoolYearNum");

    var data = {
        schoolYearNum: schoolYearNum,
        schoolId: schoolId
    };

    commonAjax(getSubjectConstructionListUrl, data, "addSubjectConstruction", "GET");
}

function addSubjectConstruction(res) {
    var resultData = res.obj;

    var subjectConstructionDoctorHtml = "";
    var subjectConstructionPostGraduateHtml = "";

    for (var i = 0; i < resultData.length; i++) {
        if (resultData[i].type == "DOCTOR") {
            subjectConstructionDoctorHtml += "<tr subjectConstructionId='" + resultData[i].id + "'>";
            subjectConstructionDoctorHtml += "<td><span>" + resultData[i].subjectConstructionName + "</span></td>";
            subjectConstructionDoctorHtml += "<td><span>" + resultData[i].grade + "</span></td>";
            subjectConstructionDoctorHtml += "<td><span>" + resultData[i].professionalDirection + "</span></td>";
            subjectConstructionDoctorHtml += "<td><a data-toggle='modal' data-target='#myModal11'><span onclick=updateSubjectConstruction('" + resultData[i].id + "','doctor')>编辑</span></a></td>";
            subjectConstructionDoctorHtml += "</tr>";
        } else {
            subjectConstructionPostGraduateHtml += "<tr subjectConstructionId='" + resultData[i].id + "'>";
            subjectConstructionPostGraduateHtml += "<td><span>" + resultData[i].subjectConstructionName + "</span></td>";
            subjectConstructionPostGraduateHtml += "<td><span>" + resultData[i].grade + "</span></td>";
            subjectConstructionPostGraduateHtml += "<td><span>" + resultData[i].professionalDirection + "</span></td>";
            subjectConstructionPostGraduateHtml += "<td><a data-toggle='modal' data-target='#myModal13'><span onclick=updateSubjectConstruction('" + resultData[i].id + "','postGraduate')>编辑</span></a>&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;<a><span onclick=deleteSubjectConstruction('" + resultData[i].id + "')>删除</span></a></td>";
            subjectConstructionPostGraduateHtml += "</tr>";
        }
    }

    $("#subjectConstructionDoctor").html(subjectConstructionDoctorHtml);
    $("#subjectConstructionPostGraduate").html(subjectConstructionPostGraduateHtml);
}

function updateSubjectConstruction(subjectConstructId, type) {
    var data = {
        id: subjectConstructId
    };
    commonAjax(getSubjectConstructionBySubjectConstructionIdUrl, data, "getSubjectConstructionBySubjectConstructionId", "GET", type);
}

function deleteSubjectConstruction(subjectConstructionId) {
    var data = {
        id: subjectConstructionId
    };

    commonAjax(deleteSubjectConstructionUrl, data, "deleteSubjectConstructionById", "POST");
}

function deleteSubjectConstructionById(res) {
    if (res.obj == "SUCCESS") {
        alert("删除成功！");
        location.reload();
    } else {
        alert("删除失败！");
    }
}

function getSubjectConstructionBySubjectConstructionId(res, type) {
    var resultData = res.obj;
    if (type == "doctor") {
        $("#updateSubjectConstructionDoctorSubjectConstructionName").val(resultData.subjectConstructionName);
        if (resultData.grade == 1) {
            $("#updateSubjectConstructionDoctorGrade").html("<option sGrade='" + 1 + "'>一级</option><option sGrade='" + 2 + "'>二级</option>");
        } else {
            $("#updateSubjectConstructionDoctorGrade").html("<option sGrade='" + 2 + "'>二级</option><option sGrade='" + 1 + "'>一级</option>");
        }
        $("#updateSubjectConstructionDoctorProfessionalDirection").val(resultData.professionalDirection);
        $("#updateSubjectConstructionDoctorButton").html("<button type='button' class='btn btn-default' data-dismiss='modal'>取消</button><button type='button' class='btn btn-danger'><span onclick=saveAndFlushSubjectConstruction('" + resultData.id + "','DOCTOR')>保存</span></button>");
    } else {
        $("#updateSubjectConstructionPostGraduateSubjectConstructionName").val(resultData.subjectConstructionName);
        if (resultData.grade == 1) {
            $("#updateSubjectConstructionPostGraduateGrade").html("<option sGrade='" + 1 + "'>一级</option><option sGrade='" + 2 + "'>二级</option>");
        } else {
            $("#updateSubjectConstructionPostGraduateGrade").html("<option sGrade='" + 2 + "'>二级</option><option sGrade='" + 1 + "'>一级</option>");
        }
        $("#updateSubjectConstructionPostGraduateProfessionalDirection").val(resultData.professionalDirection);
        $("#updateSubjectConstructionPostGraduateButton").html("<button type='button' class='btn btn-default' data-dismiss='modal'>取消</button><button type='button' class='btn btn-danger'><span onclick=saveAndFlushSubjectConstruction('" + resultData.id + "','POSTGRADUATE')>保存</span></button>");
    }
}

function saveAndFlushSubjectConstruction(subjectConstructionId, type) {
    var subjectConstructionName = "";
    var grade = "";
    var professionalDirection = "";
    if (type == "DOCTOR") {
        subjectConstructionName = $("#updateSubjectConstructionDoctorSubjectConstructionName").val();
        grade = $("#updateSubjectConstructionDoctorGrade option:selected").attr("sGrade");
        professionalDirection = $("#updateSubjectConstructionDoctorProfessionalDirection").val();
    } else if (type == "POSTGRADUATE") {
        subjectConstructionName = $("#updateSubjectConstructionPostGraduateSubjectConstructionName").val();
        grade = $("#updateSubjectConstructionPostGraduateGrade option:selected").attr("sGrade");
        professionalDirection = $("#updateSubjectConstructionPostGraduateProfessionalDirection").val();
    }

    var data = {
        id: subjectConstructionId,
        subjectConstructionName: subjectConstructionName,
        grade: grade,
        professionalDirection: professionalDirection
    };

    commonAjax(updateSubjectConstructionUrl, data, "updateSubjectConstructionResult", "POST");
}

function updateSubjectConstructionResult(res) {
    if (res.obj == "SUCCESS") {
        alert("操作成功！");
        location.reload();
    } else {
        alert("操作失败！");
        return;
    }
}

function addSubjectConstructionDoctor(type) {
    var theSendType = type;
    var subjectConstructionName = "";
    var grade = "";
    var professionalDirection = "";
    if (type == "DOCTOR") {
        theSendType = "DOCTOR";
        subjectConstructionName = $("#addSubjectConstructionDoctorSubjectConstructionName").val();
        grade = parseInt($("#addSubjectConstructionDoctorGrade option:selected").attr("sGrade"));
        professionalDirection = $("#addSubjectConstructionDoctorProfessionalDirection").val();
    } else if (type == "POSTGRADUATE") {
        theSendType = "POSTGRADUATE";
        subjectConstructionName = $("#addSubjectConstructionPostGraduateSubjectConstructionName").val();
        grade = parseInt($("#addSubjectConstructionPostGraduateGrade option:selected").attr("sGrade"));
        professionalDirection = $("#addSubjectConstructionPostGraduateProfessionalDirection").val();
    }
    var schoolYearNum = $("#subjectConstructionSchoolYear option:selected").attr("schoolYearNum");

    var data = {
        subjectConstructionName: subjectConstructionName,
        grade: grade,
        professionalDirection: professionalDirection,
        schoolYearNum: schoolYearNum,
        typeEnum: theSendType,
        schoolId: schoolId
    };

    commonAjax(addSubjectConstructionUrl, data, "addSubjectConstructionResult", "POST");
}

function addSubjectConstructionResult(res) {
    if (res.obj == "SUCCESS") {
        alert("操作成功！");
        location.reload();
    } else {
        alert("操作失败！");
        return;
    }
}

// 获取思政类课程建设情况
function getIdeologicalAndPoliticalEducationCourse() {
    var schoolYearNum = $("#curriculumConstructionSchoolYear option:selected").attr("schoolYearNum");

    var data = {
        schoolYearNum: schoolYearNum,
        schoolId: schoolId
    };

    commonAjax(listCurriculumConstructionUrl, data, "listCurriculumConstruction", "GET");
}

function listCurriculumConstruction(res) {
    var resultData = res.obj;
    var listCurriculumConstructionHtml = "";
    for (var i = 0; i < resultData.length; i++) {
        listCurriculumConstructionHtml += "<tr curriculumConstructionId='" + resultData[i].id + "'>";
        listCurriculumConstructionHtml += "<td><span>" + resultData[i].curriculumConstructionName + "</span></td>";
        listCurriculumConstructionHtml += "<td><span>" + resultData[i].curriculumNature + "</span></td>"
        listCurriculumConstructionHtml += "<td><span>" + resultData[i].theNumberOfClasses + "</span></td>";
        listCurriculumConstructionHtml += "<td><span>" + resultData[i].annualElectiveNumber + "</span></td>";
        listCurriculumConstructionHtml += "<td><span>" + resultData[i].studentLevel + "</span></td>"
        listCurriculumConstructionHtml += "<td><a data-toggle='modal' data-target='#myModal15'><span onclick=updateCurriculumConstruction('" + resultData[i].id + "')>编辑</span></a>&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;<a><span onclick=deleteCurriculumConstruction('" + resultData[i].id + "')>删除</span></a></td>"
        listCurriculumConstructionHtml += "</tr>"
    }
    $("#listCurriculumConstruction").html(listCurriculumConstructionHtml);
}
function deleteCurriculumConstruction(curriculumConstructionId) {
    var data = {
        id: curriculumConstructionId
    };

    commonAjax(deleteCurriculumConstructionByIdUrl, data, "updateCurriculumConstructionResult", "POST");
}
function updateCurriculumConstruction(curriculumConstructionId) {
    var data = {
        id: curriculumConstructionId
    };

    commonAjax(getCurriculumConstructionByIdUrl, data, "getCurriculumConstructionById", "GET");
}

function getCurriculumConstructionById(res) {
    var resultData = res.obj;
    $("#updateCurriculumConstructionCurriculumConstructionName").val(resultData.curriculumConstructionName);
    $("#updateCurriculumConstructionCurriculumNature").val(resultData.curriculumNature);
    $("#updateCurriculumConstructionTheNumberOfClasses").val(resultData.theNumberOfClasses);
    $("#updateCurriculumConstructionAnnualElectiveNumber").val(resultData.annualElectiveNumber);
    $("#updateCurriculumConstructionStudentLevel").val(resultData.studentLevel);
    $("#updateCurriculumConstructionButton").html("<button type='button' class='btn btn-default' data-dismiss='modal'>取消</button><button type='button' class='btn btn-danger'><span onclick=updateCurriculumConstructionById('" + resultData.id + "')>保存</span></button>");
}

function updateCurriculumConstructionById(curriculumConstructionId) {
    var curriculumConstructionName = $("#updateCurriculumConstructionCurriculumConstructionName").val();
    var curriculumNature = $("#updateCurriculumConstructionCurriculumNature").val();
    var theNumberOfClasses = $("#updateCurriculumConstructionTheNumberOfClasses").val();
    var annualElectiveNumber = $("#updateCurriculumConstructionAnnualElectiveNumber").val();
    var studentLevel = $("#updateCurriculumConstructionStudentLevel").val();

    var data = {
        id: curriculumConstructionId,
        curriculumConstructionName: curriculumConstructionName,
        curriculumNature: curriculumNature,
        theNumberOfClasses: theNumberOfClasses,
        annualElectiveNumber: annualElectiveNumber,
        studentLevel: studentLevel
    };

    commonAjax(updateCurriculumConstructionUrl, data, "updateCurriculumConstructionResult", "POST");
}

function updateCurriculumConstructionResult(res) {
    if (res.obj == "SUCCESS") {
        alert("操作成功！");
        location.reload();
    } else {
        alert("操作失败！");
        return;
    }
}

function addCurriculumConstruction() {
    var schoolYearNum = $("#curriculumConstructionSchoolYear option:selected").attr("schoolYearNum");
    var curriculumConstructionName = $("#addCurriculumConstructionCurriculumConstructionName").val();
    var curriculumNature = $("#addCurriculumConstructionCurriculumNature").val();
    var theNumberOfClasses = $("#addCurriculumConstructionTheNumberOfClasses").val();
    var annualElectiveNumber = $("#addCurriculumConstructionAnnualElectiveNumber").val();
    var studentLevel = $("#addCurriculumConstructionStudentLevel").val();

    var data = {
        schoolYearNum: schoolYearNum,
        curriculumConstructionName: curriculumConstructionName,
        curriculumNature: curriculumNature,
        theNumberOfClasses: theNumberOfClasses,
        annualElectiveNumber: annualElectiveNumber,
        studentLevel: studentLevel,
        schoolId: schoolId
    }

    commonAjax(addCurriculumConstructionUrl, data, "addCurriculumConstructionResult", "POST");
}

function addCurriculumConstructionResult(res) {
    if (res.obj == "SUCCESS") {
        alert("操作成功！");
        location.reload();
    } else {
        alert("操作失败！");
        return;
    }
}

// 获取本校动态
function listSchoolDynamics() {
    var schoolYearNum = $("#schoolDynamicsSchoolYear option:selected").attr("schoolYearNum");

    var data = {
        schoolYearNum: schoolYearNum,
        schoolId: schoolId
    };
//    data='{"schoolYearNum":"'+schoolYearNum+'","type":"DYNAMICS","schoolId":'+schoolId+'}';

    commonAjax(listSchoolDynamicsUrl, data, "getSchoolDynamicsList", "POST");
}

function getSchoolDynamicsList(res) {
    var resultData = res.obj;
    var schoolDynamicsListHtml = "";

    for (var i = 0; i < resultData.length; i++) {
        var status = "";

        if (resultData[i].upDownType == "UP") {
            status = "已开启"
        } else if (resultData[i].upDownType == "DOWN") {
            status = "已关闭";
        }

        schoolDynamicsListHtml += "<tr>";
        schoolDynamicsListHtml += "<td><span>" + resultData[i].title + "</span></td>";
        schoolDynamicsListHtml += "<td><span>" + changeTimeSchoolDynamics(resultData[i].creatTime) + "</span></td>";
        schoolDynamicsListHtml += "<td><span>" + resultData[i].brief + "</span></td>";
        // if (resultData[i].upDownType == "UP") {
        //     schoolDynamicsListHtml += "<td>" + status + "&nbsp;&nbsp;|&nbsp;&nbsp;<a><span onclick=changeSchoolDynamicsStatus('DOWN','" + resultData[i].id + "')>关闭</span></a></td>";
        // } else {
        //     schoolDynamicsListHtml += "<td>" + status + "&nbsp;&nbsp;|&nbsp;&nbsp;<a><span onclick=changeSchoolDynamicsStatus('UP','" + resultData[i].id + "')>开启</span></a></td>";
        // }
        schoolDynamicsListHtml += "<td><a data-target='#myModal17' data-toggle='modal'><span onclick=getSchoolDynamicsByIdRequest('" + resultData[i].id + "')>编辑</span></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a><span onclick=deleteSchoolDynamics('" + resultData[i].id + "')>删除</span></a></td>";
        schoolDynamicsListHtml += "</tr>"
    }
    $("#schoolDynamicsList").html(schoolDynamicsListHtml);
}

// function changeSchoolDynamicsStatus(status, schoolDynamicsId) {
//     var data = {
//         upDownType: status,
//         id: schoolDynamicsId
//     };
//
//     commonAjax(changeSchoolDynamicsUpDownTypeUrl, data, "changeSchoolDynamicsUpDownTypeRes", "POST");
// }

function deleteSchoolDynamics(id) {
    var data = {
        id: id
    };

    commonAjax(deleteSchoolDynamicsUrl, data, "deleteSchoolDynamicsResult", "POST");
}

function deleteSchoolDynamicsResult(res) {
    if (res.obj == "SUCCESS") {
        alert("操作成功！");
        location.reload();
    } else {
        alert("操作失败！");
        return;
    }
}

function addSchoolDynamics() {
    var formData = new FormData();
    formData.append("title", $("#title").val());
    formData.append("schoolId", parseInt(schoolId));
    var type = $("#schoolDynamicsTypes option:selected").attr("schoolDynamicsType");
    formData.append("myType", type);
    formData.append("schoolYearNum", $("#schoolDynamicsSchoolYear option:selected").attr("schoolYearNum"));
    formData.append("content", editor.txt.html());
    formData.append("brief", $("#brief").val());
    formData.append("file", $("#schoolDynamicsPic")[0].files[0]);

    console.log(formData);

    $.ajax({
        type: 'POST',
        url: addSchoolDynamicsUrl,
        data: formData,
        processData: false,
        contentType: false,
        success: function (result) {
            addSchoolDynamicsRes(result);
        },
        error: function (err) {
        }
    });
}

function addSchoolDynamicsRes(res) {
    if (res.obj == "SUCCESS") {
        alert("操作成功！");
        location.reload();
    } else {
        alert("操作失败！");
        return;
    }
}

function getSchoolDynamicsByIdRequest(id) {
    var data = {
        id: id
    };

    commonAjax(getSchoolDynamicsByIdUrl, data, "getSchoolDynamicsByIdRequestRes", "GET");
}

function getSchoolDynamicsByIdRequestRes(res) {
    var resultData = res.obj;

    $("#updateTitle").val(resultData.title);
    updateEditor.txt.html(resultData.content);
    $("#updateBrief").val(resultData.brief);
    $("#updateSchoolDynamicsSlPic").attr("src", resultData.pic);
    var updateSchoolDType = "";
    if (resultData.type == "DYNAMICS") {
        updateSchoolDType = '<option schoolDynamicsType="DYNAMICS">高校动态</option>';
    } else if (resultData.type == "HARVEST") {
        updateSchoolDType = '<option schoolDynamicsType="HARVEST">成果展示</option>';
    } else if (resultData.type == "OPINION") {
        updateSchoolDType = '<option schoolDynamicsType="OPINION">专家观点</option>';
    } else if (resultData.type == "RESEARCH") {
        updateSchoolDType = '<option schoolDynamicsType="RESEARCH">专题研究</option>';
    } else if (resultData.type == "REPORT") {
        updateSchoolDType = '<option schoolDynamicsType="REPORT">会议报告</option>';
    }
    $("#updateSchoolDynamicsTypes").html(updateSchoolDType + '<option schoolDynamicsType="DYNAMICS">高校动态</option><option schoolDynamicsType="HARVEST">成果展示</option><option schoolDynamicsType="OPINION">专家观点</option><option schoolDynamicsType="RESEARCH">专题研究</option><option schoolDynamicsType="REPORT">会议报告</option>');

    $("#schoolDynamicsUpdate").html('<button type="button" class="btn btn-default" data-dismiss="modal">取消</button><button type="button" class="btn btn-danger" onclick=updateSchoolDynamics("' + resultData.id + '")>保存</button>');
}

function updateSchoolDynamics(id) {
    var title = $("#updateTitle").val();
    var content = updateEditor.txt.html();
    var brief = $("#updateBrief").val();
    var file = $("#updateSchoolDynamicsPic")[0].files[0];

    var type = $("#updateSchoolDynamicsTypes option:selected").attr("schoolDynamicsType");

    var formData = new FormData();

    formData.append("title", title);
    formData.append("content", content);
    formData.append("brief", brief);
    formData.append("id", id);
    formData.append("myType", type);
    if (typeof(file) != "undefined")
        formData.append("file", file);

    $.ajax({
        type: 'POST',
        url: updateSchoolDynamicsUrl,
        data: formData,
        processData: false,
        contentType: false,
        success: function (result) {
            updateSchoolDynamicsRes(result);
        },
        error: function (err) {
        }
    });
}

function updateSchoolDynamicsRes(res) {
    if (res.obj == "SUCCESS") {
        alert("操作成功！");
        location.reload();
    } else {
        alert("操作失败！");
        return;
    }
}

/*********************************** Util ***********************************/

// 教师性别枚举转换
function changeTeacherSex(sex) {
    if (sex == "M" || sex == "男") {
        return "男";
    } else if (sex == "F" || sex == "女") {
        return "女";
    } else {
        return "";
    }
}

// 教师职称枚举转换
function changeTeacherPositionalEnum(positional) {
    if (positional == "PROFESSOR") {
        return "教授";
    } else if (positional == "ASSOCIATE_PROFESSOR") {
        return "副教授";
    } else if (positional == "LECTURER") {
        return "讲师"
    } else if (positional == "INSTRUCTOR") {
        return "辅导员";
    } else if (positional == "教授") {
        return "PROFESSOR";
    } else if (positional == "副教授") {
        return "ASSOCIATE_PROFESSOR";
    } else if (positional == "讲师") {
        return "LECTURER";
    } else if (positional == "辅导员") {
        return "INSTRUCTOR";
    } else {
        return "";
    }
}

// 教师职务枚举转换
function changeTeacherDuties(duties) {
    if (duties == "YUAN_ZHANG") {
        return "院长";
    } else if (duties == "FU_YUAN_ZHANG") {
        return "副院长";
    } else if (duties == "SHU_JI") {
        return "书记";
    } else if (duties == "FU_SHU_JI") {
        return "副书记";
    } else if (duties == "KE_YAN_SHI_ZHU_REN") {
        return "科研室主任";
    } else if (duties == "XUE_KE_DAI_TOU_REN") {
        return "学科带头人";
    } else if (duties == "WU") {
        return "无";
    } else if (duties == "院长") {
        return "YUAN_ZHANG";
    } else if (duties == "副院长") {
        return "FU_YUAN_ZHANG";
    } else if (duties == "书记") {
        return "SHU_JI";
    } else if (duties == "副书记") {
        return "FU_SHU_JI";
    } else if (duties == "科研室主任") {
        return "KE_YAN_SHI_ZHU_REN";
    } else if (duties == "学科带头人") {
        return "XUE_KE_DAI_TOU_REN";
    } else if (duties == "无") {
        return "WU";
    } else {
        return "";
    }
}

// 教师学历枚举转换
function changeTeacherEducation(education) {
    if (education == "UNDERGRADUATE") {
        return "本科";
    } else if (education == "POSTGRADUATE") {
        return "硕士"
    } else if (education == "DOCTOR") {
        return "博士";
    } else if (education == "本科") {
        return "UNDERGRADUATE";
    } else if (education == "硕士") {
        return "POSTGRADUATE";
    } else if (education == "博士") {
        return "DOCTOR";
    } else {
        return "";
    }
}

// 课程选修、必修转换
function changeCourseRequiredElective(requiredElective) {
    if (requiredElective == "REQUIRED") {
        return "必修";
    } else if (requiredElective == "ELECTIVE") {
        return "选修";
    }
}

function changeTimeBirth(timeStr) {
    var date = new Date(timeStr);
    var dateYear = date.getFullYear();
    var dateMonth = date.getMonth() + 1;
    var dateDay = date.getDate();
    var hour = date.getHours();
    var min = date.getMinutes();
    // var dateStr = dateYear + "年" + dateMonth + "月" + dateDay + "日 " + hour + ":" + min;
    // var dateStr = dateYear + "-" + dateMonth + "-" + dateDay;
    var dateStr = dateYear + "-" + dateMonth;
    return dateStr;
}// 转换时间

function changeTimeSchoolDynamics(timeStr) {
    var date = new Date(timeStr);
    var dateYear = date.getFullYear();
    var dateMonth = date.getMonth() + 1;
    var dateDay = date.getDate();
    var hour = date.getHours();
    var min = date.getMinutes();
    var dateStr = dateYear + "-" + dateMonth + "-" + dateDay + " " + hour + ":" + min;
    // var dateStr = dateYear + "-" + dateMonth + "-" + dateDay;
    // var dateStr = dateYear + "-" + dateMonth;
    return dateStr;
}// 转换时间

// 限制字符串长度
function limitLength(wantLength, str) {
    var returnStr = "";
    var realLength = 0;
    var len = (str != null) ? str.length : 0;
    var charCode = -1;
    for (var i = 0; i < len; i++) {
        if (realLength < wantLength) {
            charCode = str.charCodeAt(i);
            if (charCode >= 0 && charCode <= 128)
                realLength += 1;
            else
                realLength += 2;
            returnStr += str.charAt(i);
        } else {
            returnStr += "...";
            break;
        }
    }
    return returnStr;
}

// 判空
function juge(obj) {
    for (i in obj) {
        var value = "";

        if (obj[i] == null || obj[i] == undefined) {
            eval("obj." + i + "=''");
        }
    }
    return obj;
}